package com.example.eback.dao;

import com.example.eback.entity.Article;
import com.example.eback.resultmap.ViewArtAndUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArticleDAO extends JpaRepository<Article,Long> {
    @Query("SELECT new com.example.eback.resultmap.ViewArtAndUser(a, u) FROM Article a, User u WHERE a.artUserId = u.id and a.artTypeId=:typeId")
    List<ViewArtAndUser>findAllByArtTypeId(Long typeId);

    @Query("SELECT new com.example.eback.resultmap.ViewArtAndUser(a, u) FROM Article a, User u WHERE a.artUserId = u.id ")
    Page<ViewArtAndUser>findViewArtAndUser(Pageable pageable);

    @Query("SELECT new com.example.eback.resultmap.ViewArtAndUser(a, u) FROM Article a, User u WHERE a.artUserId = u.id")
    Page<ViewArtAndUser>findViewArtAndUserMain(Pageable pageable);

    List<Article>findAllByArtUserId(Long userId);

}
